Understanding Endpoints in RTK Query
In RTK Query, endpoints define the operations your application can perform with an API — such as fetching, creating, updating, or deleting data. Each endpoint describes how a specific request should be made and how RTK Query should cache or update the response.
Query endpoints: Used for fetching and reading data from an API. Defined using builder.query().
Mutation endpoints: Used for creating, updating, or deleting data. Defined using builder.mutation().
Define the API routes and request configurations for each operation.
Automatically generate React hooks like useGetUsersQuery or useAddUserMutation.
Control caching, invalidation, and refetching behavior for specific data sets.
Allow strong typing and automatic inference when using TypeScript.
Endpoints are the core building blocks of RTK Query APIs, defining how your application interacts with backend services in a clean, declarative way.